PIC24F
TIMER Peripheral Module Library Help


Table Of Contents

1     Library Features. 3

2     Using Library Functions in Your Code. 3

3     Functions. 3

3.1        CloseTimerX (X = 1 … 5 ) 3

3.2        ConfigIntTimerX (X = 1 … 5 ) 4

3.3        OpenTimerX (X = 1 … 5 ) 4

3.4        ReadTimerX (X = 1 … 5 ) 5

3.5        WriteTimerX (X = 1 … 5 ) 5

3.6        CloseTimer23 , CloseTimer45. 5

3.7        ConfigIntTimer23 , ConfigIntTimer45. 6

3.8        OpenTimer23 , OpenTimer45. 6

3.9        ReadTimer23 , ReadTimer45. 7

3.10       WriteTimer23 , WriteTimer45. 7

4     Macros. 7

4.1        EnableIntTX (X = 1 to 5) 7

4.2        DisableIntTX (X = 1 to 5) 7

4.3        SetPriorityIntTX (X = 1 to 5)(priority) 8

 


1          Library Features

 

For this peripheral library module:

 

·         The Timer1 module is a 16-bit timer , Timer2/3 and Timer4/5 modules are 32-bit timers, which can also be configured as four independent 16-bit  timers with selectable operating modes.

·         Timer 1 operates in CPU Idle modes and Sleep modes.

·         Individually, Timer2/3 and Timer4/5 of the 16-bit timers can function as synchronous timers or counters.

·         ADC Event Trigger is implemented only with Timer5.

 

2          Using Library Functions in Your Code

 

Library routine parameters can be constructed using either AND based mask or AND_OR based mask setting. For more information on these masks, see 16-bit Peripheral Libraries.

 

Examples of use for both the methods are below.

 

Example of Use ( AND mask )

 

   OpenTimer1((T1_ON & T1_IDLE_CON & T1_GATE_ON & T1_PS_1_8 &

               T1_SYNC_EXT_ON & T1_SOURCE_INT), PR1_VALUE);

 

Example of Use ( AND_OR mask )

 

Function Call:

 

#define USE_AND_OR        /* To enable AND_OR mask setting */

#include<timer.h>

   /*

    …

    User code

    …

   */

    OpenTimer1((T1_ON | T1_IDLE_CON | T1_GATE_ON | T1_PS_1_8 |

                T1_SYNC_EXT_ON | T1_SOURCE_INT), PR1_VALUE);

 

   /*

    …

    User code

    …

   */

 

3          Functions

3.1         CloseTimerX (X = 1 … 5 )

 

Function Prototype

void CloseTimer1(void);

void CloseTimer2(void);

void CloseTimer3(void);

void CloseTimer4(void);

void CloseTimer5(void);

Include

timer.h

Description

This function turns off the 16-bit timer module.

Arguments

None

Return Value

None

Remarks:

This function first disables the 16-bit timer interrupt and then turns off the timer module. The Interrupt Flag bit (TxIF) is also cleared.

Source File:

CloseTimer1.c

CloseTimer2.c

CloseTimer3.c

CloseTimer4.c

CloseTimer5.c

3.2         ConfigIntTimerX (X = 1 … 5 )

 

Function Prototype

void ConfigIntTimer1(unsigned int config);

void ConfigIntTimer2(unsigned int config);

void ConfigIntTimer3(unsigned int config);

void ConfigIntTimer4(unsigned int config);

void ConfigIntTimer5(unsigned int config);

Include

timer.h

Description

This function configures the 16-bit timer interrupt.

Arguments

config - Timer interrupt priority and enable/disable information as defined below:

   Tx_INT_PRIOR_7

   Tx_INT_PRIOR_6

   Tx_INT_PRIOR_5

   Tx_INT_PRIOR_4

   Tx_INT_PRIOR_3

   Tx_INT_PRIOR_2

   Tx_INT_PRIOR_1

   Tx_INT_PRIOR_0

   Tx_INT_ON

   Tx_INT_OFF

Return Value

None

Remarks:

This function clears the 16-bit Interrupt Flag (TxIF) bit and then sets the interrupt priority and enables/disables the interrupt.

Source File:

ConfigIntTimer1.c

ConfigIntTimer2.c

ConfigIntTimer3.c

ConfigIntTimer4.c

ConfigIntTimer5.c

3.3         OpenTimerX (X = 1 … 5 )

 

Function Prototype

void OpenTimer1(unsigned int config,

   unsigned int period);

void OpenTimer2(unsigned int config,

   unsigned int period);

void OpenTimer3(unsigned int config,

   unsigned int period);

void OpenTimer4(unsigned int config,

   unsigned int period);

void OpenTimer5(unsigned int config,

   unsigned int period);

Include

timer.h

Description

This function configures the 16-bit timer module.

Arguments

config - The parameters to be configured in the TxCON register as defined below:

Timer Module On/Off

   Tx_ON

   Tx_OFF

Timer Module Idle mode On/Off

   Tx_IDLE_CON

   Tx_IDLE_STOP

Timer Gate time accumulation enable

   Tx_GATE_ON

   Tx_GATE_OFF

Timer prescaler

   Tx_PS_1_1

   Tx_PS_1_8

   Tx_PS_1_64

   Tx_PS_1_128

Timer Synchronous clock enable

   Tx_SYNC_EXT_ON

   Tx_SYNC_EXT_OFF

Timer clock source

   Tx_SOURCE_EXT

   Tx_SOURCE_INT

 

period - The period match value to be stored into the PR register

 

Return Value

None

Remarks:

This function configures the 16-bit Timer Control register and sets the period match value into the PR register.

Source File:

OpenTimer1.c

OpenTimer2.c

OpenTimer3.c

OpenTimer4.c

OpenTimer5.c

3.4         ReadTimerX (X = 1 … 5 )

 

Function Prototype

unsigned int ReadTimer1(void);

unsigned int ReadTimer2(void);

unsigned int ReadTimer3(void);

unsigned int ReadTimer4(void);

unsigned int ReadTimer5(void);

Include

timer.h

Description

This function reads the contents of the 16-bit Timer register.

Arguments

None

Return Value

None

Remarks:

This function returns the contents of the 16-bit TMR register.

Source File:

ReadTimer1.c

ReadTimer2.c

ReadTimer3.c

ReadTimer4.c

ReadTimer5.c

3.5         WriteTimerX (X = 1 … 5 )

 

Function Prototype

void WriteTimer1(unsigned int timer);

void WriteTimer2(unsigned int timer);

void WriteTimer3(unsigned int timer);

void WriteTimer4(unsigned int timer);

void WriteTimer5(unsigned int timer);

Include

timer.h

Description

This function writes the 16-bit value into the Timer register.

Arguments

timer - The 16-bit value to be stored into TMR register.

Return Value

None

Remarks:

None

Source File:

WriteTimer1.c

WriteTimer2.c

WriteTimer3.c

WriteTimer4.c

WriteTimer5.c

3.6         CloseTimer23 , CloseTimer45

 

Function Prototype

void CloseTimer23 (void);

void CloseTimer45 (void);

Include

timer.h

Description

This function turns off the 32-bit timer module.

Arguments

None

Return Value

None

Remarks:

This function disables the 32-bit timer interrupt and then turns off the timer module.The Interrupt Flag bit (TxIF) is also cleared.

CloseTimer23 turns off Timer2 and disables Timer3 Interrupt.

CloseTimer45 turns off Timer4 and disables Timer5 Interrupt.

Source File:

CloseTimer23.c

CloseTimer45.c

3.7         ConfigIntTimer23 , ConfigIntTimer45

 

Function Prototype

void ConfigIntTimer23(unsigned int config);

void ConfigIntTimer45(unsigned int config);

Include

timer.h

Description

This function configures the 32-bit timer interrupt.

Arguments

config - Timer interrupt priority and enable/disable information as defined below:

   Tx_INT_PRIOR_7

   Tx_INT_PRIOR_6

   Tx_INT_PRIOR_5

   Tx_INT_PRIOR_4

   Tx_INT_PRIOR_3

   Tx_INT_PRIOR_2

   Tx_INT_PRIOR_1

   Tx_INT_PRIOR_0

   Tx_INT_ON

   Tx_INT_OFF

Return Value

None

Remarks:

This function clears the 32-bit Interrupt Flag (TxIF) bit and then sets the interrupt priority and enables/disables the interrupt.

Source File:

ConfigIntTimer23.c

ConfigIntTimer45.c

3.8         OpenTimer23 , OpenTimer45

 

Function Prototype

void OpenTimer23(unsigned int config,

   unsigned long period);

void OpenTimer45(unsigned int config,

   unsigned long period);

Include

timer.h

Description

This function configures the 32-bit timer interrupt.

Arguments

config - This contains the parameters to be configured in the TxCON register as defined below:

Timer module On/Off

   Tx_ON

   Tx_OFF

Timer Module Idle mode On/Off

   Tx_IDLE_CON

   Tx_IDLE_STOP

Timer Gate time accumulation enable

   Tx_GATE_ON

   Tx_GATE_OFF

Timer prescaler

   Tx_PS_1_1

   Tx_PS_1_8

   Tx_PS_1_64

   Tx_PS_1_128

Timer Synchronous clock enable

   Tx_SYNC_EXT_ON

   Tx_SYNC_EXT_OFF

Timer clock source

   Tx_SOURCE_EXT

   Tx_SOURCE_INT

period - This contains the period match value to be stored into the 32-bit PR register.

Return Value

None

Remarks:

This function configures the 32-bit Timer Control register and sets the period match value into the PR register.

Source File:

OpenTimer23.c

OpenTimer45.c

3.9         ReadTimer23 , ReadTimer45

 

Function Prototype

unsigned long ReadTimer23(void);

unsigned long ReadTimer45(void);

Include

timer.h

Description

This function reads the contents of the 32-bit Timer register.

Arguments

None

Return Value

None

Remarks:

This function returns the contents of the 32-bit TMR register.

Source File:

ReadTimer23.c

ReadTimer45.c

3.10     WriteTimer23 , WriteTimer45

 

Function Prototype

void WriteTimer23(unsigned long timer);

void WriteTimer45(unsigned long timer);

Include

timer.h

Description

This function writes the 32-bit value into the Timer register.

Arguments

timer - The 32-bit value to be stored into TMR register.

Return Value

None

Remarks:

This function returns the contents of the 32-bit TMR register.

Source File:

ReadTimer23.c

ReadTimer45.c

 

4          Macros

4.1         EnableIntTX (X = 1 to 5)

 

Macro

EnableIntT1

EnableIntT2

EnableIntT3

EnableIntT4

EnableIntT5

Include

uart.h

Description

This macro enables the timer interrupt.

Arguments

None

Remarks

This macro sets Timer Interrupt Enable bit of Interrupt Enable Control register.

4.2         DisableIntTX (X = 1 to 5)

 

Macro

DisableIntT1

DisableIntT2

DisableIntT3

DisableIntT4

DisableIntT5

Include

uart.h

Description

This macro disables the timer interrupt.

Arguments

None

Remarks

This macro clears Timer Interrupt Enable bit of Interrupt Enable Control register.

4.3         SetPriorityIntTX (X = 1 to 5)(priority)

 

Macro

SetPriorityIntT1

SetPriorityIntT2

SetPriorityIntT3

SetPriorityIntT4

SetPriorityIntT5

Include

uart.h

Description

This macro sets priority for timer interrupt.

Arguments

priority

Remarks

This macro sets Timer Interrupt Priority bits of Interrupt Priority Control register.